package test5.lupeng.jf.com.teamdemo.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import test5.lupeng.jf.com.teamdemo.R;
import test5.lupeng.jf.com.teamdemo.bean.response.UserListResponse;

/**
 * Created by C-yx on 2017/8/1.
 */

public class UserListAdapter  extends RecyclerView.Adapter{
    ArrayList<UserListResponse.ResultBean> mResultBeen  ;

    public UserListAdapter(ArrayList<UserListResponse.ResultBean> mResultBeen) {
        this.mResultBeen = mResultBeen;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_userlist,parent,false);
        ItemViewHolder holder  = new ItemViewHolder(view);
        return holder;
    }

    class ItemViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_headImage;
        TextView tv_username;
        TextView tv_sign;
        public ItemViewHolder(View itemView) {
            super(itemView);
            iv_headImage= itemView.findViewById(R.id.iv_headImage);
            tv_username= itemView.findViewById(R.id.tv_username);
            tv_sign= itemView.findViewById(R.id.tv_sign);
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
           final UserListResponse.ResultBean bean = mResultBeen.get(position);
           ItemViewHolder viewHolder = (ItemViewHolder) holder;
        viewHolder.tv_username.setText(bean.getUsername());
        viewHolder.tv_sign.setText(bean.getSignature());
        Glide.with(holder.itemView.getContext()).load(bean.getHeadProtrait())
                .asBitmap()
                .into(viewHolder.iv_headImage);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mChooseListener!=null){
                    mChooseListener.setChoose(bean);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mResultBeen.size();
    }

    public   interface  ChooseListener{
        void  setChoose(UserListResponse.ResultBean bean);
    }

    private ChooseListener mChooseListener;
    public void setChooseListener(ChooseListener ChooseListener){
        mChooseListener=ChooseListener;
    }
}
